﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Globalization;

/// <summary>
/// Summary description for CommonHelper
/// </summary>
public class CommonHelper
{
	public CommonHelper()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static string RutGonString(string str, int num)
    {
        string result = "";
        string[] str_array = str.Split(' ');
        if (str_array.Length <= num)
        {
            return str;
        }
        if (str_array != null)
        {
            for (int i = 0; i < str_array.Length; i++)
            {
                result += " " + str_array[i];
                if (i == num - 1)
                {
                    break;
                }
            }
        }
        return result + "...";
    }

    public static string RutGonStringVer2(string str, int totalNumBerCharacter)
    {
        string swap = string.Empty;
        string result = "";
        if (str.Length > totalNumBerCharacter)
        {
            string[] str_array = str.Split(' ');
            for (int i = 0; i < str_array.Length - 1; i++)
            {
                swap = result;
                if ((result += " " + str_array[i]).Length > totalNumBerCharacter)
                {
                    result = swap;
                    break;
                }
                
            }
            return result + "...";
        }
        return str;

        
    }

    public static string ConvertDate(object NgayDangTin, string type)
    {
        try
        {
            CultureInfo ci = new CultureInfo("vi-VN");
            DateTime m_date = Convert.ToDateTime(NgayDangTin);
            string result = "";
            switch (type)
            {
                case Constants.UserUI:
                    result = m_date.ToString("dddd, dd-MM-yyyy hh:mm",ci);
                    break;
                case Constants.AdminUI:
                    result = m_date.ToString("dd/MM/yyyy hh:mm",ci);
                    break;
                case "vietnam":
                    result = m_date.ToString("dd/MM/yyyy", ci);
                    break;
                default:
                    break;
            }
            return result;
        }
        catch (Exception)
        {

            return null;
        }
    }
}
